<script type="text/javascript">
	var is_apply = false;
	function save(){
		var options = {
			beforeSubmit:  showRequest,  // pre-submit callback
			success:       showResponse  // post-submit callback
		};
		
		$('#cdAnAdmincp').val(oEditCdAn.getHTMLBody());
		$('#thucDonAdmincp').val(oEditThucDon.getHTMLBody());
		$('#chamSocAdmincp').val(oEditChamSoc.getHTMLBody());
		$('#vanDeAdmincp').val(oEditVanDe.getHTMLBody());
		$('#phatTrienAdmincp').val(oEditPhatTrien.getHTMLBody());
		$('#buocDemAdmincp').val(oEditBuocDem.getHTMLBody());

		$('#frmManagement').ajaxSubmit(options);
	}

	function apply(){
		is_apply = true;
		save();
	}

	function showRequest(formData, jqForm, options) {
		var form = jqForm[0];
		if(form.titleAdmincp.value == '' || 
			form.cdAnAdmincp.value == '' || form.thucDonAdmincp.value == '' ||
			form.chamSocAdmincp.value == '' || form.vanDeAdmincp.value == '' ||
			form.phatTrienAdmincp.value == '' || form.buocDemAdmincp.value == '' ||
			form.weekAdmincp.value == '' || isNaN(form.weekAdmincp.value)){
			alert('Vui lòng điền đúng & đầy đủ thông tin.');
			$('#loader').fadeOut(300);
			show_perm_denied();
			return false;
		}
	}

	function showResponse(responseText, statusText, xhr, $form) {
		if(responseText=='success'){
			if(is_apply == true){
				location.reload();
			} else {
				location.href=root+"admincp/"+module+"/#/save";
			}
		}
		
		if(responseText=='permission-denied'){
			show_perm_denied();
		}
		
		if(responseText=='File not support'){
			alert('File not support');
			$('#loader').fadeOut(300);
			show_perm_denied();
		}
		
	}

	// Config editor
	function config_editor(editor){
		editor.width = '732px';
		editor.height = '425px';
		editor.cmdAssetManager="modalDialogShow('"+root+"static/editor/assetmanager/assetmanager.php',640,445);";
		editor.css="<?=PATH_URL.'static/css/tv_app/detail.css?r=3'?>";
	}

</script>
<div class="gr_perm_error" style="display:none;">
	<p><strong>FAILURE: </strong><span id="txt_error">Permission Denied.</span></p>
</div>
<div class="table">
	<div class="head_table"><div class="head_title_edit"><?=$module?></div></div>
	<div class="clearAll"></div>

	<form id="frmManagement" action="<?=PATH_URL.'admincp/'.$module.'/save/'?>" method="post" enctype="multipart/form-data">
		<input type="hidden" value="<?=$id?>" name="hiddenIdAdmincp" id="hiddenIdAdmincp" />
		<div class="row_text_field_first">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Status:</td>
					<td class="right_text_field"><input <?php if(isset($result->status)){ if($result->status==1){ ?>checked="checked"<?php }}else{ ?>checked="checked"<?php } ?> type="checkbox" class="custom_chk" name="statusAdmincp" /></td>
				</tr>
			</table>
		</div>

		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Month From:</td>
					<td class="right_text_field"><input value="<?php if(isset($result->week)) { print $result->week; }else{ print '';} ?>" type="text" name="weekAdmincp" /></td>
				</tr>
			</table>
		</div>

		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Month To:</td>
					<td class="right_text_field"><input value="<?php if(isset($result->week_to)) { print $result->week_to; }else{ print '';} ?>" type="text" name="weekToAdmincp" /></td>
				</tr>
			</table>
		</div>

		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Title:</td>
					<td class="right_text_field"><input value="<?php if(isset($result->title)) { print $result->title; }else{ print '';} ?>" type="text" name="titleAdmincp" /></td>
				</tr>
			</table>
		</div>
		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Chế độ ăn:</td>
					<td class="right_text_field" style="padding-right: 0px;">
						<textarea name="cdAnAdmincp" id="cdAnAdmincp" cols="" rows="8">
							<?php if(isset($result->cd_an)) { print $result->cd_an; }else{ print '';} ?>
						</textarea>
						<script type="text/javascript">
							var oEditCdAn = new InnovaEditor("oEditCdAn");
							config_editor(oEditCdAn);
							oEditCdAn.REPLACE("cdAnAdmincp");
						</script>
					</td>
				</tr>
			</table>
		</div>
		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Thực đơn cho bé:</td>
					<td class="right_text_field" style="padding-right: 0px;">
						<textarea name="thucDonAdmincp" id="thucDonAdmincp" cols="" rows="8">
							<?php if(isset($result->thuc_don)) { print $result->thuc_don; }else{ print '';} ?>
						</textarea>
						<script type="text/javascript">
							var oEditThucDon = new InnovaEditor("oEditThucDon");
							config_editor(oEditThucDon);
							oEditThucDon.REPLACE("thucDonAdmincp");
						</script>
					</td>
				</tr>
			</table>
		</div>
		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Chăm sóc bé:</td>
					<td class="right_text_field" style="padding-right: 0px;">
						<textarea name="chamSocAdmincp" id="chamSocAdmincp" cols="" rows="8">
							<?php if(isset($result->cham_soc)) { print $result->cham_soc; }else{ print '';} ?>
						</textarea>
						<script type="text/javascript">
							var oEditChamSoc = new InnovaEditor("oEditChamSoc");
							config_editor(oEditChamSoc);
							oEditChamSoc.REPLACE("chamSocAdmincp");
						</script>
					</td>
				</tr>
			</table>
		</div>
		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Vấn đề thường gặp</td>
					<td class="right_text_field" style="padding-right: 0px;">
						<textarea name="vanDeAdmincp" id="vanDeAdmincp" cols="" rows="8">
							<?php if(isset($result->van_de)) { print $result->van_de; }else{ print '';} ?>
						</textarea>
						<script type="text/javascript">
							var oEditVanDe = new InnovaEditor("oEditVanDe");
							config_editor(oEditVanDe);
							oEditVanDe.REPLACE("vanDeAdmincp");
						</script>
					</td>
				</tr>
			</table>
		</div>
		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Sự phát triển của bé</td>
					<td class="right_text_field" style="padding-right: 0px;">
						<textarea name="phatTrienAdmincp" id="phatTrienAdmincp" cols="" rows="8">
							<?php if(isset($result->phat_trien)) { print $result->phat_trien; }else{ print '';} ?>
						</textarea>
						<script type="text/javascript">
							var oEditPhatTrien = new InnovaEditor("oEditPhatTrien");
							config_editor(oEditPhatTrien);
							oEditPhatTrien.REPLACE("phatTrienAdmincp");
						</script>
					</td>
				</tr>
			</table>
		</div>
		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Các bước đệm cho<br/>sựphát triển của bé</td>
					<td class="right_text_field" style="padding-right: 0px;">
						<textarea name="buocDemAdmincp" id="buocDemAdmincp" cols="" rows="8">
							<?php if(isset($result->buoc_dem)) { print $result->buoc_dem; }else{ print '';} ?>
						</textarea>
						<script type="text/javascript">
							var oEditBuocDem = new InnovaEditor("oEditBuocDem");
							config_editor(oEditBuocDem);
							oEditBuocDem.REPLACE("buocDemAdmincp");
						</script>
					</td>
				</tr>
			</table>
		</div>
	</form>
</div>